package com.lovol.surfaceviewdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import com.lovol.surfaceviewdemo.databinding.ActivityThreadBinding
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

class ThreadActivity : AppCompatActivity(), Runnable {
    private val TAG = "ThreadActivity"
    lateinit var binding: ActivityThreadBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityThreadBinding.inflate(LayoutInflater.from(this))
        setContentView(binding.root)



        executorsUsage()
    }

    private fun executorsUsage() {
        val scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        scheduledExecutorService.schedule(this, 3 * 1000, TimeUnit.MILLISECONDS)
        //延时任务，并循环执行
        //Runnable command（the task to execute）
        // long initialDelay 执行第一次的延迟时间（the time to delay first execution）
        // long period 连续执行的间隔时间（the period between successive executions）
        // TimeUnit unit 前两个参数的时间单位（the time unit of the initialDelay and period parameters）
        //scheduledExecutorService.scheduleAtFixedRate(this, 100, 3 * 1000, TimeUnit.MILLISECONDS)

        //scheduledExecutorService.shutdown()
    }

    override fun run() {
        Log.i(TAG, "run: 1111")
    }
}